<?php

class categoryComponents extends sfComponents
{
	public function executePermissions()
	{
		/* @var $category Category */
		$this->arRoles = MyConstants::getRolesList();
		$category = CategoryPeer::retrieveByPk($this->getRequestParameter('id'));
		if($category)
		{
			$this->arCategorypPermissionsRoles = json_decode($category->getPermissions(), true);
	    }
		
	}
	
	public function executeStatus_id()
	{
		if( $category->getStatus_id() == MyConstants::OBJ_STATUS_ACTIVE )
		{
			return link_to(image_tag('news_active.png', __('alt="deactivate" title="Deactivate" border="0"')), 'category/deactivate?id=' . $category->getId());

		} else	{

			return link_to(image_tag('news_inactive.png', __('alt="activate" title="Activate" border="0"')), 'category/activate?id=' . $category->getId());
		}
	}

    public function executePhoto()
    {
		$this->isPhoto = false;
		$category = CategoryPeer::retrieveByPk($this->getRequestParameter('id'));
		$c = new Criteria();
		$c->add( FilesPeer::OBJ_ID,  $this->getRequestParameter('id'));
		$c->add( FilesPeer::OBJ_TYPE, MyConstants::TYPE_CATEGORY );
		$photo = FilesPeer::doSelectOne($c);
		if( $photo )
		{
			$this->isPhoto = true;
			$this->photo = $photo;
		}
    }

}
